package tq.com.tqcom.base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import tq.com.tqcom.R;
import tq.com.tqcom.vh.TQEmptyViewHold;

public class BaseRecyclerFragment extends BaseFragment {

    protected RecyclerView mRecyclerView;
    protected SmartRefreshLayout mRefreshLayout;

    protected TQEmptyViewHold mEmptyViewHold;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View lView = inflater.inflate(R.layout.fragment_recycle_layout, container, false);
        mRecyclerView = lView.findViewById(R.id.recycleView);
        initRecycleView(mRecyclerView);

        mRecyclerView.setNestedScrollingEnabled(false);
        mRecyclerView.setHasFixedSize(true);

        mRefreshLayout = lView.findViewById(R.id.refresh);
        initRefresh(mRefreshLayout);

        if(mEmptyViewHold == null){
            mEmptyViewHold = new TQEmptyViewHold(lView.findViewById(R.id.empty_view));
            mEmptyViewHold.setReloadListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    reload();
                }
            });
            mEmptyViewHold.setVisible(View.GONE);
        }
        return lView;
    }

    protected void initRecycleView(RecyclerView pRecyclerView){
    }

    protected void initRefresh(SmartRefreshLayout pRefreshLayout){
        mRefreshLayout.setEnableRefresh(false);
        mRefreshLayout.setEnableLoadMore(false);
    }

    protected void reload(){

    }

    protected void switchEmpty(boolean bSwitch){
        mRefreshLayout.setVisibility(bSwitch ? View.INVISIBLE : View.VISIBLE);
        mEmptyViewHold.setVisible(bSwitch ? View.VISIBLE : View.GONE);
    }
}
